'use strict';

const fs = require('fs'), path = require("path");

module.exports = (b, p, f)=>{
    let par = path.dirname(p).split("/"), pdep = 0, tmpp = b;

    function cd(){
        pdep++;
        tmpp += "/" + par[pdep];
        if(pdep >= par.length){
            f();
            return;
        }
        fs.stat(tmpp, function(err, stats){
            if(err && err.code == 'ENOENT'){
                fs.mkdir(tmpp, function(){
                    cd();
                });
                return;
            }
            cd();
        });
    }
    cd();
}